package com.dzxcqmxm.Dao.impl.testServletContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 在test2读数据
 *
 */
public class test2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ServletContext context = this.getServletContext();
        //获取数据，类似键值对，需要通过键名获取
        String username=(String) context.getAttribute("username");
        //设置编码格式
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        //输出数据
        resp.getWriter().print(username);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
